package com.meilai.project.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpingMvcConfig implements WebMvcConfigurer {

    @Autowired
    WebInterceptor webInterceptor;
    @Autowired
    MiniInterceptor miniInterceptor;
    @Autowired
    AppInterceptor appInterceptor;



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加一个拦截器，连接以/admin为前缀的 url路径
//        registry.addInterceptor(authInterceptor).addPathPatterns("/app/**","/dictionary/tax-types/pid/**","/bank/create-card/**");

        registry.addInterceptor(webInterceptor).addPathPatterns("/api/web/**");

        registry.addInterceptor(miniInterceptor).addPathPatterns("/api/mini/**");

        registry.addInterceptor(appInterceptor).addPathPatterns("/api/app/**");


    }

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        try {
            File path = new File(ResourceUtils.getURL("classpath:").getPath());
            if(!path.exists()) path = new File("");
            registry.addResourceHandler("/storage/**")
                    .addResourceLocations("file:"+ path.getAbsolutePath() +"/storage/");
            registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        }
        catch (Exception e){
            e.printStackTrace();
        }


    }*/
}
